package adverts_api

import (
	"fmt"
	"gin_study_blog/common"
	"gin_study_blog/common/http"
	"gin_study_blog/models"

	"github.com/gin-gonic/gin"
)

func (AdvertsApi) AdvertsDeleteView(c *gin.Context) {
	var re models.RemoveRequest

	err := c.ShouldBindJSON(&re)
	if err != nil {
		http.FailWithCode(http.ParamsError, c)
		return
	}
	var advertsList []*models.AdvertModel
	// 查询文件是否存在数据库中
	count := common.DB.Find(&advertsList, re.IdList).RowsAffected
	if count == 0 {
		http.FailWithMessage("文件不存在", c)
		return
	}
	// 在删除数据库数据
	common.DB.Delete(&advertsList)
	http.IsOkWithMessage(fmt.Sprintf("共删除 %d 张图片", count), c)
}
